<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.Order;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.Order">
		<cfargument name="Order_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.Order_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new Order();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				local.loadArgs.Deleted = 0;
				return load(argumentCollection = local.loadArgs);
			} else {
				return new Order();
			}
		</cfscript>
	</cffunction>

	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.Order">
		<cfargument name="obj" type="assets.calgrants.com.bo.Order" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.Order_ID")) {
				local.obj.setOrder_ID(arguments.Order_ID);
			}
			if (IsDefined("arguments.Program_Year")) {
				local.obj.setProgram_Year(arguments.Program_Year);
			}
			if (IsDefined("arguments.Approved")) {
				local.obj.setApproved(arguments.Approved); 
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted); 
			}
			if (IsDefined("arguments.Organization_ID")) {
				local.obj.setOrganization_ID(arguments.Organization_ID); 
			}
			if (IsDefined("arguments.Ordered_By_ID")) {
				local.obj.setOrdered_By_ID(arguments.Ordered_By_ID); 
			}
			if (IsDefined("arguments.Anticipated_Ship_Date")) {
				local.obj.setAnticipated_Ship_Date(arguments.Anticipated_Ship_Date); 
			}
			if (IsDefined("arguments.Fulfillment_Date")) {
				local.obj.setFulfillment_Date(arguments.Fulfillment_Date); 
			}
			if (IsDefined("arguments.Student_Count")) {
				local.obj.setStudent_Count(arguments.Student_Count); 
			}
			if (IsDefined("arguments.Volunteer_Count")) {
				local.obj.setVolunteer_Count(arguments.Volunteer_Count); 
			}
			if (IsDefined("arguments.Order_Value_IDs")) {
				local.obj.setOrder_Value_IDs(arguments.Order_Value_IDs); 
			}
			if (IsDefined("arguments.Quantities")) {
				local.obj.setQuantities(arguments.Quantities); 
			}
			if (IsDefined("arguments.Shipping_Organization")) {
				local.obj.setShipping_Organization(arguments.Shipping_Organization); 
			}
			if (IsDefined("arguments.Shipping_Department")) {
				local.obj.setShipping_Department(arguments.Shipping_Department); 
			}
			if (IsDefined("arguments.Shipping_Name")) {
				local.obj.setShipping_Name(arguments.Shipping_Name); 
			}
			if (IsDefined("arguments.Shipping_Address")) {                             
				local.obj.setShipping_Address(arguments.Shipping_Address);
			}
			if (IsDefined("arguments.Shipping_City")) {
				local.obj.setShipping_City(arguments.Shipping_City);
			}
			if (IsDefined("arguments.Shipping_State")) {
				local.obj.setShipping_State(arguments.Shipping_State);
			}
			if (IsDefined("arguments.Shipping_Zip_Code")) {
				local.obj.setShipping_Zip_Code(arguments.Shipping_Zip_Code);
			}
			if (IsDefined("arguments.Shipping_Phone")) {
				local.obj.setShipping_Phone(arguments.Shipping_Phone);
			}
			if (IsDefined("arguments.Shipping_Instructions")) {
				local.obj.setShipping_Instructions(arguments.Shipping_Instructions);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}			
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="Order_ID" required="false" default="" />
		<cfargument name="Program_Year" required="false" default="" />
		<cfargument name="Approved" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Organization_ID" required="false" default="" />
		<cfargument name="Ordered_By_ID" required="false" default="" />
		<cfargument name="Anticipated_Ship_Date" required="false" default="" />
		<cfargument name="Fulfillment_Date" required="false" default="" />
		<cfargument name="Student_Count" required="false" default="" />
		<cfargument name="Volunteer_Count" required="false" default="" />
		<cfargument name="Order_Value_IDs" required="false" default="" />
		<cfargument name="Quantities" required="false" default="" />
		<cfargument name="Shipping_Organization" required="false" default="" />
		<cfargument name="Shipping_Department" required="false" default="" />
		<cfargument name="Shipping_Name" required="false" default="" />
		<cfargument name="Shipping_Address" required="false" default="" />
		<cfargument name="Shipping_City" required="false" default="" />
		<cfargument name="Shipping_State" required="false" default="" />
		<cfargument name="Shipping_Zip_Code" required="false" default="" />
		<cfargument name="Shipping_Phone" required="false" default="" />
		<cfargument name="Shipping_Instructions" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />
		<cfargument name="organizationIDs" required="false" default="" />
		<cfargument name="regionIDs" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readOrder">
			<cfprocparam value="#arguments.Order_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Order_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Program_Year#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Program_Year)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Approved)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Organization_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Organization_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Ordered_By_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Ordered_By_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Anticipated_Ship_Date#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.Anticipated_Ship_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Fulfillment_Date#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.Fulfillment_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Student_Count#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Student_Count)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Volunteer_Count#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Volunteer_Count)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Order_Value_IDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Order_Value_IDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Quantities#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Quantities)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Organization#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Organization)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Department#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Department)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Name)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Address#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Address)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_City#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_City)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_State#" cfsqltype="CF_SQL_CHAR" null="#IIf(Len(Trim(arguments.Shipping_State)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Zip_Code#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Zip_Code)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Phone#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Phone)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Instructions#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Instructions)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.organizationIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.organizationIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.regionIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.regionIDs)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="order" required="true" type="assets.calgrants.com.bo.Order" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveOrder">
			<cfprocparam value="#order.getOrder_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#order.getProgram_Year()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getApproved()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#order.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#order.getOrganization_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#order.getOrdered_By_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#formatShortDate(order.getAnticipated_Ship_Date())#" cfsqltype="CF_SQL_DATE" null="false" />
			<cfprocparam value="#formatShortDate(order.getFulfillment_Date())#" cfsqltype="CF_SQL_DATE" null="#IIf(NOT IsDate(order.getFulfillment_Date()), true, false)#" />
			<cfprocparam value="#order.getStudent_Count()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#order.getVolunteer_Count()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#order.getOrder_Value_IDs()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getQuantities()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getShipping_Organization()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getShipping_Organization())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShipping_Department()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getShipping_Department())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShipping_Name()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getShipping_Address()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getShipping_City()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getShipping_State()#" cfsqltype="CF_SQL_CHAR" null="false" />
			<cfprocparam value="#formatZipCode(order.getShipping_Zip_Code())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#formatPhone(order.getShipping_Phone())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getShipping_Instructions()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getShipping_Instructions())) eq 0, true, false)#" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="Order_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroyOrder">
			<cfprocparam value="#arguments.Order_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

